package com.rong.action;

import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.rong.DAO.ZynPrice34DAO;
import com.rong.ORM.ZynPrice34;
import com.rong.ORM.ZynQueryPrice;
import com.rong.ORM.ZynUser;
import com.rong.hibernate.Const;

public class Price34Action extends ActionSupport {

		ZynPrice34 price34=new ZynPrice34();
		ZynPrice34DAO price34Dao=new ZynPrice34DAO();
		private List<ZynPrice34> list;
		private String saveFlag="";
		private int id=-1; // the Price34 id indatabase.
		

		private int rowsPerPage =25;// 每页显示几条
		private int page = 1; // 默认当前页
		private int totalPage;// 总共多少页
		private int planNum;// 总过多少条
		
		ZynQueryPrice queryCrt=new ZynQueryPrice();
		
		/**
		 * @return the price34
		 */
		public ZynPrice34 getPrice34() {
			return price34;
		}
		/**
		 * @param price34 the price34 to set
		 */
		public void setPrice34(ZynPrice34 price34) {
			this.price34 = price34;
		}
		/**
		 * @return the list
		 */
		public List<ZynPrice34> getList() {
			return list;
		}
		/**
		 * @param list the list to set
		 */
		public void setList(List<ZynPrice34> list) {
			this.list = list;
		}
		/**
		 * @return the saveFlag
		 */
		public String getSaveFlag() {
			return saveFlag;
		}
		/**
		 * @param saveFlag the saveFlag to set
		 */
		public void setSaveFlag(String saveFlag) {
			this.saveFlag = saveFlag;
		}
		/**
		 * @return the id
		 */
		public int getId() {
			return id;
		}
		/**
		 * @param id the id to set
		 */
		public void setId(int id) {
			this.id = id;
		}
		
		

		/**
		 * @return the rowsPerPage
		 */
		public int getRowsPerPage() {
			return rowsPerPage;
		}
		/**
		 * @param rowsPerPage the rowsPerPage to set
		 */
		public void setRowsPerPage(int rowsPerPage) {
			this.rowsPerPage = rowsPerPage;
		}
		/**
		 * @return the page
		 */
		public int getPage() {
			return page;
		}
		/**
		 * @param page the page to set
		 */
		public void setPage(int page) {
			this.page = page;
		}
		/**
		 * @return the totalPage
		 */
		public int getTotalPage() {
			return totalPage;
		}
		/**
		 * @param totalPage the totalPage to set
		 */
		public void setTotalPage(int totalPage) {
			this.totalPage = totalPage;
		}
		/**
		 * @return the planNum
		 */
		public int getPlanNum() {
			return planNum;
		}
		/**
		 * @param planNum the planNum to set
		 */
		public void setPlanNum(int planNum) {
			this.planNum = planNum;
		}
		/**
		 * @return the queryCrt
		 */
		public ZynQueryPrice getQueryCrt() {
			return queryCrt;
		}
		/**
		 * @param queryCrt the queryCrt to set
		 */
		public void setQueryCrt(ZynQueryPrice queryCrt) {
			this.queryCrt = queryCrt;
		}
		@Override
	    public String execute() throws Exception {
	        this.setSaveFlag("");
	        //价格所属分公司
	        ActionContext actionContext = ActionContext.getContext();         
	        Map session = actionContext.getSession(); 
	        ZynUser loguser=(ZynUser) session.get("loginUser");    // the user session
	        this.price34.setExtAttr3(String.valueOf(loguser.getComId()));
	        
	        //价格所属分公司
			price34Dao.save(this.price34);        //保存注册的price34对象
			 this.setSaveFlag("保存成功..");
	        return SUCCESS;
	    }
		 public String findall() throws Exception {
		        
			 ActionContext actionContext = ActionContext.getContext();         
	         Map session = actionContext.getSession(); 
	         ZynUser loguser=(ZynUser) session.get("loginUser");    // the user session
	         if(loguser.getZyncom().getComProperty().equalsIgnoreCase(Const.comTypetop)){//公司本部可以查看所有
	        	 this.setList(price34Dao.findAll());        //全部
	         }else{
	        	 this.setList(price34Dao.findByExtAttr3(String.valueOf(loguser.getComId())));        //所有分公司单价列表
	         }
			 
		        return "success_list";
		    }
		 public String findbyid() throws Exception {
		        
			this.setPrice34(price34Dao.findById(this.getId()));// find the price34 by id	
			//this.setCarlist(carDao.findAll());        //保存注册的user对象
			// this.setComlist(comDao.findAll());        //保存注册的user对象
		        return "s_find_one";
		       
		    }
		 public String edit() throws Exception {
		      			
			   price34Dao.merge(this.getPrice34());// edit the price34 by id			
			    return "s_edit_one";
			    }
		 public String delete() throws Exception {
		        
				price34Dao.delete(price34Dao.findById(this.getId()));// delete the price34 by id			
			    return "s_delete_one";
			    }
		 public String toGetPriceList() throws Exception {
			  
				this.setList(price34Dao.findPriceQueryByPage(page, rowsPerPage,this.queryCrt));       
		        this.setPlanNum(price34Dao.priceTatolRows(this.queryCrt).size());
		        this.setTotalPage(this.getPlanNum() % this.getRowsPerPage()==0?this.getPlanNum()/this.getRowsPerPage():this.getPlanNum()/this.getRowsPerPage()+1);     
			        return "success_list";
			    }
			 

}
